package com.mzjf.boot.controller;

import com.mzjf.boot.common.PageVo;
import com.mzjf.boot.entity.Sysuser;
import com.mzjf.boot.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 测试查询数据库返回列表
 * @Author wuhongpu
 * @Date 2018-05-02 14:59
 * http://192.168.10.129:8085/swagger-ui.html#/
 */
@RestController
@Api(value = "Swagger UserService", description = "演示Swagger用法的Control类", tags = "Swagger UserService Tag")
public class UserController {
    @Autowired
    private UserService userService;

     @ApiOperation("返回用户列表信息")
     @RequestMapping("/user")
    public PageVo lists() {

         return userService.selectUser();
    }

    //ApiOperation 方法描述
    @ApiOperation(value = "根据id获取记录", response = PageVo.class)
    @RequestMapping(value = "/queryById", method = {RequestMethod.POST, RequestMethod.GET})
    // 定义请求参数 required = true 必写
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "id", value = "主键", required = true) })
    public PageVo queryById(Integer id) {
        PageVo pageVo= userService.selectUserById(id);
        return pageVo;
    }

    // 方法说明  @ApiParam：用于Controller中方法的参数说明
    @ApiOperation(value = "添加用户记录", response = Integer.class)
    @RequestMapping(value = "/add", method = {RequestMethod.POST, RequestMethod.GET})
    public int add(@ApiParam(value="添加的学生") Sysuser sysuser){
        System.out.println("add sysUser="+"用户添加完成");
        return 1;
    }

    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    // 方法说明
    @ApiOperation(value = "添加学生记录", notes="传递复杂对象DTO",produces = "application/json")
    public int update(@RequestBody Sysuser sysuser){
        System.out.println("update student = " + sysuser);
        return 1;
    }

    // 方法说明
    @ApiOperation(value = "删除用户信息")
    @RequestMapping(value = "/del", method = {RequestMethod.POST, RequestMethod.GET})
    // 定义返回值意义
    @ApiResponses({
            @ApiResponse(code = 400, message = "服务器内部异常"),
            @ApiResponse(code = 500, message = "权限不足") })
    public int del(int id){
        System.out.println("del id = " + id);
        return 1;
    }


}
